#pragma once
#include "TinyTalkState.h"
#include "TinyServerDefine.h"

namespace TalkProcess {
class CTalkObject
{
public:
	CTalkObject(void);
	virtual ~CTalkObject(void);

	//virtual void changeState(CDeviceState * state);
	template<typename T>
	void changeState(const T& state)
	{
		CTinyTalkState* pState = g_TalkStatePool.createState(state);
		if(pState == NULL)
		{
			return;
		}
		if(m_CurrentState!= NULL)
		{
			delete m_CurrentState;
			m_CurrentState = pState;
			return;
		}
		else
			m_CurrentState = pState;

		m_CurrentState->talkObjectHandle = this;

		return;

	}
	virtual CTinyTalkState* getState(void);

	virtual void ProcessReceivedMsg(CTinyMsg& inMsg,CTinyMsg& OutMsg)
	{
		if(m_CurrentState != NULL)
			m_CurrentState->ProcessReceivedMsg(inMsg,OutMsg);
	}

	std::string& GetTalkID(){return m_TalkID;}
protected:
	CTinyTalkState* m_CurrentState ;
	std::string			m_TalkID;
};
}